import Vue from 'vue'
import Vuex from 'vuex'
import layout from './modules/layout';
import api from '../service';

Vue.use(Vuex)

export interface DirectionState {
  template: any[];
  data: any[];
}

export interface State {
  direction: DirectionState
}

export default new Vuex.Store({
  modules: {
    layout
  },
  state: {
    direction: {}
  },
  actions: {
    async load(context, payload) {

      let response = await api.fetchDirectionData()
      if (response.length !== 0) {
        context.commit('load', response[0])
      }
    }
  },
  mutations: {
    load(state, payload: DirectionState) {
      state.direction = { ...state.direction, template: payload.template, data: payload.data }
    }
  },
  strict: true
})
